package com.kaikai.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kaikai.commonutils.R;
import com.kaikai.edu.entity.EduCourse;
import com.kaikai.edu.entity.EduTeacher;
import com.kaikai.edu.service.EduCourseService;
import com.kaikai.edu.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("eduservice/frontTeacher")
public class EduTeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;
    @GetMapping("{page}/{limit}")
    public R pageList(@PathVariable Long page,@PathVariable Long limit){

        Page<EduTeacher> pageTeacher=new Page<>(page,limit);
        //此时,需要返回所有分页数据
        Map<String,Object> map=teacherService.getTeacherFrontList(pageTeacher);
        return R.ok().data(map);
    }

    //根据讲师id获取讲师基本信息和课程信息
    @GetMapping("getInfoById/{teacherId}")
    public R getInfoById(@PathVariable String teacherId){
        EduTeacher teacher = teacherService.getById(teacherId);
        QueryWrapper<EduCourse> wrapper=new QueryWrapper<>();
        wrapper.eq("teacher_id", teacherId);
        List<EduCourse> courseList = courseService.list(wrapper);
        return R.ok().data("teacher",teacher).data("courseList",courseList);
    }


}
